<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}

$opid = mysql_real_escape_string($_REQUEST['intoptionid']);
				
// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit") {				
				$taxrat = mysql_real_escape_string($_REQUEST['taxrate']);
				$insert="INSERT INTO `tblproductoptions` (`intoptionid`, `varoptionname`, `intlanguageid`) VALUES ('$opid','$taxrat', '1')";
				$sql=$obj_db->insert($insert);
				header("location:prodattrdetails.php?msg=add&intoptionid=$opid");
				die();
}

// UPDATE the record
$txrat = "";
$action=1;

if((isset($_REQUEST['a']) && trim($_REQUEST['a'])==2) && (!(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit"))) {
 	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid'])!="") {
		$screen_id =  mysql_real_escape_string($_REQUEST['intid']);
		$sql = "select * from tblproductoptions where intid=$screen_id";
		$result = $obj_db->select($sql);
		
		if(count($result)<=0) {
			echo " No Record Found!<br>";
			die();
		}
		
		if($result)	{
			foreach($result as $row)
			{
				$txrat = stripslashes($row['varoptionname']);
				$action=2;
			}
		}
		
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Edit") {
			$taxrat = mysql_real_escape_string($_REQUEST['taxrate']);
			$sql_upd ="UPDATE `tblproductoptions` SET `intoptionid` = '$opid', `varoptionname` = '$taxrat'	where intid ='$screen_id'";						 
			$result = $obj_db->edit($sql_upd);
			$action=1;
			header("location:prodattrdetails.php?msg=edit&intoptionid=$opid");
			die();
		}
	}
}


//DELETE record from database
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3) {
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!="")) {	
		$id =  mysql_real_escape_string($_REQUEST['intid']);
		$sql= "DELETE FROM `tblproductoptions` WHERE `intid` ='$id'";
		$query1 = mysql_query($sql);
		header("location:prodattrdetails.php?msg=del&intoptionid=$opid");
		die();
	}
}

?>
<?php include("inc/header.php");?>
<body>
<script language="javascript" src="js/prodattrdetails.js"></script>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF" class="middlebackground">
<tr>
<td align="center" valign="top" ><?php include(INC."top.inc.php");?></td>
</tr>
<tr>
<td valign="top">
<form name="prodattrdetails" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
	<td valign="top">
	  <?php   
   if(isset($_REQUEST['script'])) {
	if(trim($_REQUEST['script'])=='addprodattrdetails' || trim($_REQUEST['script'])=='editprodattrdetails') {
	?>
	  <table width="46%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
      <tr class="bg1">
        <td colspan="5" align="center"><strong>
          <?php if($_REQUEST['script']=='addprodattrdetails'){echo "Add New Product Details...";}
	if($_REQUEST['script']=='editprodattrdetails'){echo "Edit Product Details...";}?>
        </strong></td>
      </tr>
      <tr>
        <td width="4%">&nbsp;</td>
        <td width="26%" align="left">&nbsp;</td>
        <td width="3%">&nbsp;</td>
        <td width="63%" align="right">(* All fields are Required)</td>
        <td width="4%">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td align="right" class="sltimg">*Option Value </td>
        <td>:</td>
        <td align="left"><input name="taxrate" type="text" id="taxrate" value="<?php echo stripslashes($txrat);?>"/></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="5" align="left">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="5" align="center"><input name="Submit" type="submit" class="btn" id="Submit" value="<?php echo ($action==2) ? "Edit":"Submit"; ?>" onClick="return check();"/></td>
      </tr>
      <tr>
        <td colspan="5" align="center">&nbsp;</td>
      </tr>
    </table>
	<?php
	}
} else {
?>
	<table width="50%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
      <tr class="bg1">
	  <?php
	  //if(isset($_REQUEST['intoptionid']) && isset($_REQUEST['intoptionid'])!="") {
	  //	$pid=mysql_real_escape_string($_REQUEST['intoptionid']);
	  //}	
	  ?>
        <td colspan="3" align="left"><strong class="bg1">Options Value Details...</strong></td>
        <td align="center"><a href="prodattrdetails.php?script=addprodattrdetails&amp;intoptionid=<?php echo stripslashes($opid);?>" class="aa">[NEW]</a></td>
        <td align="center"><a href="#" Title="Click here to Go Back" onClick="history.go(-1);" class="aa">Go BACK</a></td>
      </tr>
      <tr class="tblbg3">
        <td align="center">Option Name </td>
        <td align="center"><strong>Option Values</strong></td>
        <!--<td align="center"><strong>Tax Rate</strong></td>
        <td align="center"><strong>Tax Desc</strong></td>-->
        <td colspan="2" align="center"><strong>Edit</strong></td>
        <td align="center"><strong>Delete</strong></td>
      </tr>
<?php
   		$sql="select * from tbloptionvalues where intid=".mysql_real_escape_string($_REQUEST['intoptionid']);
		$result=$obj_db->select($sql);
  		if($result)
		{
   		for($i=0;$i<count($result);$i++)
   		{
            $id=$result[$i]['intid'];
		/**************************************
				PAGING CODE START
		**************************************/
			//$rowperpage=23;
			$tablename="tblproductoptions";
			$per_page_keywords= "intoptionid=".$_REQUEST['intoptionid'];
			$per_page_sorts="";
			include("system/paging.inc.php"); 

		/**************************************
				PAGING CODE ENDING
		**************************************/

	//$sql="SELECT * FROM tblproductoptions WHERE intoptionid=".$_REQUEST['intoptionid'];
	
		$sql = "SELECT * 
		from  ".$tablename."	
		where ".$per_page_keywords."	
		Limit ".($page_no*$row_per_page).",".$row_per_page;
	
	$resman = $obj_db->select($sql);
	
	if(count($resman)>0)
	{
		for($m=0;$m<count($resman);$m++)
		{
?>
		<tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onmouseout="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
		<td align="center"><?php echo stripslashes($result[$i]['varoptionvaluename']);?></td>
        <td align="center"><?php echo stripslashes($resman[$m]['varoptionname']);?></td>
		<td colspan="2" align="center"><a class="link" Title="Click here to Edit" href="prodattrdetails.php?script=editprodattrdetails&amp;a=2&amp;intid=<?php echo stripslashes($resman[$m]['intid']); ?>&amp;intoptionid=<?php echo stripslashes($opid);?>"><img src="images/edit.bmp" border="0"/></a></td>
        <td align="center"><a Title="Click here to Delete" href="prodattrdetails.php?a=3&amp;intid=<?php echo stripslashes($resman[$m]['intid']); ?>&amp;intoptionid=<?php echo stripslashes($opid);?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
		</tr>	
<?php
		}
	}
?>       
      
      <?php }}?>
      <tr>
        <td colspan="10" align="center"><?php pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page);?></td>
      </tr>
    </table>
    
    <?php } //}?></td>
  </tr>
</table>
</form>

</td>
</tr>
<tr><td align="center">&nbsp;</td>
</tr>
</table>
</body>
</html>

